package com.ronan.common.entity.message;

import com.ronan.common.constant.Constants;
import lombok.extern.slf4j.Slf4j;

/**
 * FileName    : com.ronan.common.entity
 * Description :
 *
 * @author : ronan
 * @version : 1.0
 * Create Date : 2021/3/12 16:32
 **/
@Slf4j
public enum BodyEnum {

    TXT(Constants.MsgTypeConstant.TXT, Txt.class),
    IMAGE(Constants.MsgTypeConstant.IMAGE, Image.class),
    VOICE(Constants.MsgTypeConstant.VOICE, Voice.class),
    VIDEO(Constants.MsgTypeConstant.VIDEO, Video.class),
    GEOGRAPHIC(Constants.MsgTypeConstant.GEOGRAPHIC, Geographic.class),
    PAPER(Constants.MsgTypeConstant.PAPER, Paper.class);

    private final int code;
    private final Class<?> clazz;

    BodyEnum(int code, Class<?> clazz) {
        this.code = code;
        this.clazz = clazz;
    }

    /**
     * 根据code获取到class
     *
     * @param code
     * @return {@link Class<?>}
     */
    public static Class<?> getClazzByCode(int code) {
        for (BodyEnum value : BodyEnum.values()) {
            if (value.code == code) {
                return value.clazz;
            }
        }
        log.error("error code : {}", code);
        throw new RuntimeException("error code : " + code);
    }
}
